﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using FrienDev.BusinessRules.ThumbnailHelper;
using FrienDev.BusinessRules;

/// <summary>
/// Summary description for AddUserImage
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class AddUserImage : System.Web.Services.WebService
{

    public AddUserImage()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }


    [WebMethod]
    public string CropImage(string value)
    {
        string[] str = value.Split('|');
        string fileName = str[0].Replace("#####","\\");
        int x1 = Convert.ToInt32(str[1]);
        int y1 = Convert.ToInt32(str[2]);
        int x2 = Convert.ToInt32(str[3]);
        int y2 = Convert.ToInt32(str[4]);
        int size = Convert.ToInt32(str[5]);
        double scale = Convert.ToDouble(str[6]);
        int lastSlashIndex = fileName.LastIndexOf('\\');
        int lastDotIndex = fileName.LastIndexOf('.');
        string bFileName = fileName.Substring(0, lastSlashIndex) + "\\B\\" + fileName.Substring(lastSlashIndex + 1, lastDotIndex - lastSlashIndex-1) + ".png";
        string sFileName = fileName.Substring(0, lastSlashIndex) + "\\S\\" + fileName.Substring(lastSlashIndex + 1, lastDotIndex - lastSlashIndex-1) + ".png";
        ImageCropHelp ich = new ImageCropHelp();
        ich.GetPart(fileName, bFileName, 0, 0, 150, 190, x1, y1, 1);
        ich.GetPart(fileName, sFileName, 0, 0, 45, 45, x2, y2, scale);

        return "0";
    }

}

